﻿@model ThumpThumpBus.Models.ViewModels.ReportIncidentViewModel
<h3>
    Incident Report Form:</h3>
<p>
    We know you want to do. Come on just tell us who messed up. Why not right? They
    probably deserve it anyway.
</p>
@using (Html.BeginForm())
{
    <h5>
        Assailant</h5>
    @Html.DropDownListFor(x => x.SelectedAssailantId, new SelectList(Model.People, "PersonId", "PersonName", Model.SelectedAssailantId))
    <h5>
        Victim</h5>
    @Html.DropDownListFor(x => x.SelectedVictimId, new SelectList(Model.People, "PersonId", "PersonName", Model.SelectedVictimId))

    <h5>
        Reason</h5>
    @Html.EditorFor(x => x.Reason)
            
    <div>
        <input id="SubmitButton" type="submit" value="Throw" />
    </div>
}
<script type="text/javascript">
    $(document).ready(function () {
        $("#SubmitButton").click(function (event) {
            event.preventDefault();
            var vId = $("#SelectedVictimId").val();
            var aId = $("#SelectedAssailantId").val();
            var r = $("#Reason").val();
            var data = { assailantId: aId, victimId: vId, reason: r };

            jQuery.ajaxSettings.traditional = true;
            $.ajax({
                url: "/api/IncidentService",
                type: "POST",
                data: JSON.stringify(data),
                contentType: 'application/json; charset=utf-8',
                success: function () {
                    $("<p><mark>Thank for your selling out your colleague.  We will send a bus over shortly.</mark></p>").insertBefore("form");
                    $("#SelectedVictimId").val(1);
                    $("#SelectedAssailantId").val(1);
                    $("#Reason").val("");
                }
            });
        });
    });
</script>
